let storage = bui.storage();
let language,translate;
let uiList;
loader.define(function (require, exports, module, global) {
    let pageview = {
        init() {
            let qrcodeBase;
            let picClass = 'imgBJPC'
            if (isMobile()) {
                picClass = 'imgBJ'
            }
            router.$("#downloadQrcode").show()
            if (isWeiXin()) {
                router.$("#downloadQrcode").hide()
            }
            router.$("#qrcodeHb").hide()

            translate = global.translate
            language = storage.get("language", 0)
            if (!language) {
                language = 'chinese_simplified'
            }

            try {
                translate.selectLanguageTag.show = false;
                translate.ignore.id.push('languageContent')
                let curLanguage = translate.language.getCurrent()
                if (curLanguage !== language) {
                    translate.changeLanguage(language)
                }
                translate.execute();
            }catch (e) {
                console.log("切换语言报错")
            }
            if (language === "chinese_simplified") {
                router.$("#sy").css("font-size", "0.28rem")
                router.$("#provinceSelect").css("font-size", "")
                router.$("#statusSelect").css("font-size", "")
                router.$("#zdSelect").css("font-size", "")
                router.$("#lbSelect").css("font-size", "")
                router.$("#search").css("font-size", "")
            } else {
                router.$("#sy").css("font-size", "0.23rem")
                router.$("#provinceSelect").css("font-size", ".18rem")
                router.$("#statusSelect").css("font-size", ".18rem")
                router.$("#zdSelect").css("font-size", ".18rem")
                router.$("#lbSelect").css("font-size", ".18rem")
                router.$("#search").css("font-size", ".18rem")
            }
            let languageArr = storage.get('languageArr',0)
            let html = ''
            let html2 = '<select class="languageSelect" id="languageSelectId">\n'
            if (language !== 'chinese_simplified' && language !== 'english') {
                languageArr.forEach(lan => {
                    if (lan.id === language) {
                        html += '<span class="language" id="'+lan.id+'">'+lan.name+'</span>|'
                    } else {
                        html2 += '<option value="'+lan.id+'">'+lan.name+'</option>'
                    }
                })
            } else {
                languageArr.forEach(lan => {
                    html2 += '<option value="'+lan.id+'">'+lan.name+'</option>'
                })
            }
            html+= '<span class="language" id="english">English</span>|<span class="language" id="chinese_simplified">简体中文</span>'
            router.$("#languageContent").html(html + html2 + "</select>")

            router.$(".language").click(function () {
                let selectId = $(this).attr('id')
                if (selectId !== language) {
                    storage.set("language", selectId)
                    location.reload()
                }
            })
            router.$("#languageSelectId").val("");
            router.$("#languageSelectId").change(function () {
                let selectId = $(this).val()
                if (selectId !== language) {
                    storage.set("language", selectId)
                    location.reload()
                }
            })

            let uiLoading = bui.loading({
                appendTo:"#articleListLoading",
                width: 40,
                height: 40,
                opacity: 0.5,
                autoClose: false,
                text:"加载中。。。"
            });
            let uiLoadingSc = bui.loading({
                appendTo:"#articleListLoading",
                width: 40,
                height: 40,
                opacity: 0.5,
                autoClose: false,
                text:"生成中。。。"
            });
            // 自定义居中弹出框
            let scQrcodeDialog = bui.dialog({
                id: "#scQrcodeDialog",
                height: 490,
                // mask: false,
                callback: function(e) {}
            });

            let token = storage.get("token",0)
            let cate = '', glUserid = '', status = '', delFlag = '', isfix = '', isfix1 = '', title = '', ss = 0, qrcodeName = '', url = ''

            router.$("#articleListFh").click(function () {
                storage.set("tzPage", '0')
                router.replace({ url: "pages/mainIndex/mainIndex.html"});
            })

            if (token) {
                // uiLoading.show()

                router.$("#downloadQrcode").click(function () {
                    // html2canvas(document.querySelector('#qrcodeHb'), {
                    //     useCORS: true, // 【重要】开启跨域配置
                    //     scale: window.devicePixelRatio < 3 ? window.devicePixelRatio : 2,
                    //     allowTaint: true, // 允许跨域图片
                    // }).then((canvas) => {
                    //     qrcodeBase = canvas.toDataURL('image/jpeg', 1.0);

                        downloadImg(qrcodeBase,"base64");
                    // });
                })

                bui.ajax({
                    url: global.api.verifyToken,
                    method: "POST",
                    headers: {Token: token}
                }).then(function(res){
                    if (res.code != '200') {
                        uiLoading.stop()
                        bui.confirm({
                            "title": "",
                            "height": 460,
                            "content": '<div class="bui-box-center"><div><h3>登录已过期</h3></div></div>',
                            "buttons": [{ name: "确定", className: "primary-reverse" }],
                            callback:function(){
                                this.close();
                                storage.set("dlTz", '11')
                                router.replace({ url: "pages/login/login.html", param:{tzSign: '0'}});
                            }
                        });
                        try {
                            translate.execute();
                        }catch (e) {
                            console.log("切换语言报错")
                        }
                    } else {
                        let user = res.data
                        uiList = bui.list({
                            id: "#articleScrollList",
                            url: global.api.getGzhArticleList,
                            pageSize: 10, // 当pageSize 小于返回的数据大小的时候,则认为是最后一页,接口返回的数据最好能返回空数组,而不是null
                            data: {
                                cate: cate,
                                glUserid: glUserid,
                                status: status,
                                delFlag: delFlag,
                                isfix: isfix,
                                isfix1: isfix1,
                                title: title
                            },
                            headers: {Token: token},
                            //如果分页的字段名不一样,通过field重新定义
                            field: {
                                page: "page",
                                size: "limit",
                                data: "data"
                            },
                            callback: function(e) {
                                // e.target 为你当前点击的元素
                                // e.currentTarget 为你当前点击的handle 整行
                                let cla = router.$(e.target).attr("class")
                                let id = router.$(e.target).attr("name")
                                let cate = router.$(e.target).attr("cate")
                                let city = router.$(e.target).attr("city")
                                let country = router.$(e.target).attr("country")
                                let status = router.$(e.target).attr("status")
                                let delFlag = router.$(e.target).attr("delFlag")
                                let page = router.$(e.target).attr("page")
                                let glUserid = router.$(e.target).attr("glUserid")
                                let cateStr = router.$(e.target).attr("cateStr")
                                let contentText = router.$(e.target).attr("contentText")
                                let titleStr = router.$(e.target).attr("titleStr")
                                let dateStr = router.$(e.target).attr("dateStr")
                                let cityStr = router.$(e.target).attr("cityStr")
                                let imgCs = router.$(e.target).attr("imgCs")
                                let avater = router.$(e.target).attr("avater")
                                let userStr = router.$(e.target).attr("userStr")
                                let jobId = router.$(e.target).attr("jobId")

                                if (!jobId || jobId === 'null') {
                                    jobId = ''
                                }

                                if (cla) {
                                    if (cla.indexOf("edit") > -1) {
                                        //编辑
                                        storage.set('articleEditId', id)
                                        if (cate !== '1403') {
                                            router.load({ url: "pages/articleEdit/articleEdit.html", param:{tzSign: '0'}});
                                        } else {
                                            router.load({ url: "pages/articleEditEnt/articleEditEnt.html", param:{tzSign: '0'}});
                                        }
                                    } else if (cla.indexOf("delete") > -1) {
                                        //删除
                                        bui.confirm("确认要删除此信息么？", function(e) {
                                            //this 是指点击的按钮
                                            let text = $(e.target).text();

                                            if (text == "确定") {
                                                uiLoading.show()
                                                bui.ajax({
                                                    url: global.api.deleteArticle,
                                                    data:{id: id, cate: cate, city: city,status: status, page:page, country: country, jobId: jobId},
                                                    method: "POST"
                                                }).then(function(res){
                                                    if (res.code == '200') {
                                                        bui.confirm({
                                                            "title": "",
                                                            "height": 460,
                                                            "content": '<div class="bui-box-center"><div><i class="icon-successfill success"></i><h3>删除成功</h3></div></div>',
                                                            "buttons": [{ name: "我知道了", className: "primary-reverse" }],
                                                            callback: function(e) {
                                                                uiList.refresh();
                                                            }
                                                        });
                                                    } else {
                                                        bui.alert(res.msg)
                                                    }
                                                    uiLoading.stop()
                                                })
                                            }
                                            this.close()
                                        });
                                    } else if (cla.indexOf("hf") > -1) {
                                        //恢复
                                        bui.confirm("确认要恢复此信息么？", function(e) {
                                            //this 是指点击的按钮
                                            let text = $(e.target).text();

                                            if (text == "确定") {
                                                uiLoading.show()
                                                bui.ajax({
                                                    url: global.api.hfArticle,
                                                    data:{id: id, cate: cate, city: city,status: status, country: country, jobId: jobId},
                                                    method: "POST"
                                                }).then(function(res){
                                                    if (res.code == '200') {
                                                        bui.confirm({
                                                            "title": "",
                                                            "height": 460,
                                                            "content": '<div class="bui-box-center"><div><i class="icon-successfill success"></i><h3>恢复成功</h3></div></div>',
                                                            "buttons": [{ name: "我知道了", className: "primary-reverse" }],
                                                            callback: function(e) {
                                                                uiList.refresh();
                                                            }
                                                        });
                                                    }
                                                    uiLoading.stop()
                                                })
                                            }
                                            this.close()
                                        });
                                    } else if (cla.indexOf("cdsc") > -1) {
                                        //彻底删除
                                        bui.confirm("确认要彻底删除此信息么？", function(e) {
                                            //this 是指点击的按钮
                                            let text = $(e.target).text();

                                            if (text == "确定") {
                                                uiLoading.show()
                                                bui.ajax({
                                                    url: global.api.deleteArticle2,
                                                    data:{id: id, cate: cate, city: city,status: status, delFlag:delFlag, page:page, country: country, jobId: jobId},
                                                    method: "POST"
                                                }).then(function(res){
                                                    if (res.code == '200') {
                                                        bui.confirm({
                                                            "title": "",
                                                            "height": 460,
                                                            "content": '<div class="bui-box-center"><div><i class="icon-successfill success"></i><h3>彻底删除成功</h3></div></div>',
                                                            "buttons": [{ name: "我知道了", className: "primary-reverse" }],
                                                            callback: function(e) {
                                                                uiList.refresh();
                                                            }
                                                        });
                                                    } else {
                                                        bui.alert(res.msg)
                                                    }
                                                    uiLoading.stop()
                                                })
                                            }
                                            this.close()
                                        });
                                    }else if (cla.indexOf("audit") > -1) {
                                        //审核
                                        router.load({ url: "pages/audit/audit.html", param: {id: id }});
                                    }else if (cla.indexOf("cancelPc") > -1) {
                                        //取消判重
                                        bui.confirm("确认要取消判重此文章么？", function(e) {
                                            //this 是指点击的按钮
                                            let text = $(e.target).text();

                                            if (text == "确定") {
                                                uiLoading.show()
                                                bui.ajax({
                                                    url: global.api.cancelPcArticle,
                                                    data:{id: id, cate: cate, city: city,status: status, country: country},
                                                    method: "POST"
                                                }).then(function(res){
                                                    if (res.code == '200') {
                                                        bui.confirm({
                                                            "title": "",
                                                            "height": 460,
                                                            "content": '<div class="bui-box-center"><div><i class="icon-successfill success"></i><h3>取消成功</h3></div></div>',
                                                            "buttons": [{ name: "我知道了", className: "primary-reverse" }],
                                                            callback: function(e) {
                                                                uiList.refresh();
                                                            }
                                                        });
                                                    } else {
                                                        bui.alert(res.msg)
                                                    }
                                                    uiLoading.stop()
                                                })
                                            }
                                            this.close()
                                        });
                                    } else if (cla.indexOf("article") > -1) {
                                        // storage.set("articleLookId", id)
                                        // router.load({ url: "pages/articleLook/articleLook.html", param: {tzSign: '0'}});
                                        router.load({ url: "pages/articleInfo/articleInfo.html", param: {tzSign: '0', id: id, glUserid: glUserid}});
                                    } else if (cla.indexOf("scQrcode") > -1) {
                                        router.$("#showQrcodePic").hide()
                                        router.$("#typeStr").html(cateStr)
                                        router.$("#position").html(cityStr)
                                        router.$("#avater").attr("src", avater)
                                        router.$("#userName").html(userStr)
                                        router.$("#timeCity").html(dateStr + "  " + cateStr)

                                        if (contentText) {
                                            if (contentText.length > 100) {
                                                router.$("#articleContent").html(contentText.substring(0,100) + '...')
                                                router.$("#lookQw").show()
                                            } else {
                                                router.$("#articleContent").html(contentText)
                                                router.$("#lookQw").hide()
                                            }
                                        } else {
                                            router.$("#articleContent").html(titleStr)
                                            router.$("#lookQw").hide()
                                        }

                                        if (imgCs){
                                            router.$("#imgs1").show()
                                            let imgArr = imgCs.split(',')
                                            let len = imgArr.length > 3 ? 3 : imgArr.length
                                            let html = ''
                                            for (let i = 0; i < len; i++) {
                                                if (i === 0) {
                                                    html +=  '                                    <div class="span1 '+picClass+'" style="padding-left: 0">\n'
                                                } else {
                                                    html +=  '                                    <div class="span1 '+picClass+'">\n'
                                                }

                                                   html += '                                        <img src="'+imgArr[i]+'?x-oss-process=style/index" alt="">\n' +
                                                    '                                    </div>\n'
                                            }

                                            if (len < 3) {
                                                for (let i = 0; i < 3- len; i++) {
                                                    html +=  '                                    <div class="span1 '+picClass+'">\n' +
                                                        '                                    </div>\n'
                                                }
                                            }
                                            router.$("#imgs1").html(html)
                                        }

                                        uiLoadingSc.show()
                                        bui.ajax({
                                            url: global.api.createQrcode,
                                            data:{id: id, url: 'https://ty.happindo.com/#pages/articleInfo/articleInfo?id='+ id + "&glUserid=" + glUserid},
                                            method: "POST"
                                        }).then(function(res){
                                            url = res.msg
                                            // qrcodeName = id+"二维码.png"
                                            router.$("#qrcode").attr('src', url)
                                            router.$("#qrcodeHb").show()

                                            setTimeout(function () {
                                                html2canvas(router.$('#qrcodeHb')[0], {
                                                    useCORS: true, // 【重要】开启跨域配置
                                                    scale: window.devicePixelRatio < 3 ? window.devicePixelRatio : 2,
                                                    allowTaint: true, // 允许跨域图片
                                                }).then((canvas) => {
                                                    qrcodeBase = canvas.toDataURL('image/jpeg', 1.0);

                                                    router.$("#qrcodeHb").hide()
                                                    router.$("#showQrcodePic").attr('src', qrcodeBase)
                                                    router.$("#showQrcodePic").show()
                                                    scQrcodeDialog.open()
                                                    uiLoadingSc.stop()
                                                });
                                            }, 500)
                                        })
                                    }
                                }
                            },
                            template: function(data) {
                                let fontSize = '0.3rem'
                                let fontSize2 = '0.24rem'
                                let fontSize3 = '0.2rem'
                                if (language !== "chinese_simplified") {
                                    fontSize = '0.22rem'
                                    fontSize2 = '0.18rem'
                                    fontSize3 = '0.12rem'
                                }

                                ss = 1
                                let html = "";
                                data.forEach(function(el, index) {
                                    let statusStr = ''
                                    let btnStr = ''
                                    let showStr = ''
                                    let dateStr = ''

                                    if (el.sign == '0') {
                                        if (el.delFlag == '0') {
                                            if(el.status == '0'){
                                                statusStr = '审核失败'
                                                showStr = '隐藏中'
                                                dateStr = formatDate(el.ctime)
                                                if (el.error) {
                                                    statusStr +=  '(' + el.error + ')'
                                                }
                                                btnStr =  '                            <div class="bui-box">\n' +
                                                    '                                <div class="span1">\n' +
                                                    '                                    <div class="czbtn edit" style="font-size: '+fontSize2+'" name="'+el.id+'" cate="'+el.cate+'">\n' +
                                                    '                                        编辑\n' +
                                                    '                                    </div>\n' +
                                                    '                                </div>\n' +
                                                    '                                <div class="span1 btnBorder">\n' +
                                                    '                                    <div class="czbtn delete" style="font-size: '+fontSize2+'" name="'+el.id+'" cate="'+el.cate+'" city="'+el.city+'" country="'+el.country+'" status="'+el.status+'" delFlag="'+el.delFlag+'" page="'+el.page+'" jobId="'+el.jobId+'">\n' +
                                                    '                                        删除\n' +
                                                    '                                    </div>\n' +
                                                    '                                </div>\n'

                                                let cs = 0
                                                if((user.qxStr && user.qxStr.indexOf("0") > -1) || user.userId == '1' || (user.adminType && user.adminType == '0')) {
                                                    btnStr +=  '                                <div class="span1 btnBorder">\n' +
                                                        '                                    <div class="czbtn audit" style="font-size: '+fontSize2+'" name="'+el.id+'">\n' +
                                                        '                                        审核\n' +
                                                        '                                    </div>\n' +
                                                        '                                </div>\n'
                                                } else {
                                                    cs = 1
                                                }
                                                if ((user.adminType && user.adminType == '0') || user.userId == '1') {
                                                    btnStr += '                                <div class="span2 btnBorder">\n' +
                                                        '                                    <div class="czbtn cdsc" style="font-size: '+fontSize2+'" name="'+el.id+'" cate="'+el.cate+'" city="'+el.city+'" country="'+el.country+'" status="'+el.status+'" delFlag="'+el.delFlag+'" page="'+el.page+'" jobId="'+el.jobId+'">\n' +
                                                        '                                        彻底删除\n' +
                                                        '                                    </div>\n' +
                                                        '                                </div>\n'
                                                } else {
                                                    btnStr +=  '                                <div class="span1">\n' +
                                                        '                                </div>\n'
                                                    if (cs == 1) {
                                                        btnStr +=  '                                <div class="span1">\n' +
                                                            '                                </div>\n'
                                                    }
                                                }
                                                btnStr += '                        </div>\n'
                                            } else if (el.status == '1') {
                                                statusStr = '已发布'
                                                showStr = '展示中'
                                                dateStr = formatDate(el.ptime)
                                                btnStr =  '                            <div class="bui-box">\n' +
                                                    '                                <div class="span1">\n' +
                                                    '                                    <div class="czbtn edit" style="font-size: '+fontSize2+'" name="'+el.id+'" cate="'+el.cate+'">\n' +
                                                    '                                        编辑\n' +
                                                    '                                    </div>\n' +
                                                    '                                </div>\n' +
                                                    '                                <div class="span1 btnBorder">\n' +
                                                    '                                    <div class="czbtn delete" style="font-size: '+fontSize2+'" name="'+el.id+'" cate="'+el.cate+'" city="'+el.city+'" country="'+el.country+'" status="'+el.status+'" delFlag="'+el.delFlag+'" page="'+el.page+'" jobId="'+el.jobId+'">\n' +
                                                    '                                        删除\n' +
                                                    '                                    </div>\n' +
                                                    '                                </div>\n'+
                                                    '                                <div class="span2 btnBorder">\n' +
                                                    '                                    <div class="czbtn scQrcode" style="font-size: '+fontSize2+'" name="'+el.id+'" glUserid="'+el.glUserid+'" cateStr="'+el.cateStr+'" contentText="'+el.contentText+'" titleStr="'+el.title+'" dateStr="'+dateStr+'" cityStr="'+el.cityStr+'" imgCs="'+el.imgCs+'" avater="'+el.avater+'" userStr="'+el.userStr+'">\n' +
                                                    '                                        生成二维码\n' +
                                                    '                                    </div>\n' +
                                                    '                                </div>\n'

                                                let cs = 0
                                                if ((user.adminType && user.adminType == '0') || user.userId == '1') {
                                                    btnStr += '                                <div class="span2 btnBorder">\n' +
                                                        '                                    <div class="czbtn cdsc" style="font-size: '+fontSize2+'" name="'+el.id+'" cate="'+el.cate+'" city="'+el.city+'" country="'+el.country+'" status="'+el.status+'" delFlag="'+el.delFlag+'" page="'+el.page+'" jobId="'+el.jobId+'">\n' +
                                                        '                                        彻底删除\n' +
                                                        '                                    </div>\n' +
                                                        '                                </div>\n'
                                                } else {
                                                    cs = 1;
                                                }

                                                if (el.isduplicate == 1) {
                                                    showStr = '隐藏中'
                                                    if (cs == 1) {
                                                        btnStr += '                                </div>\n'+
                                                            '                            <div class="bui-box">\n' +
                                                            '                                <div class="span1">\n'
                                                    } else {
                                                        btnStr +=  '                                <div class="span2 btnBorder">\n'
                                                    }
                                                    btnStr += '                                    <div class="czbtn cancelPc" style="font-size: '+fontSize2+'" name="'+el.id+'" cate="'+el.cate+'" city="'+el.city+'" country="'+el.country+'" status="'+el.status+'" delFlag="'+el.delFlag+'" page="'+el.page+'">\n' +
                                                        '                                        取消判重\n' +
                                                        '                                    </div>\n' +
                                                        '                                </div>\n'
                                                } else {
                                                    if (cs == 0) {
                                                        btnStr += '                                <div class="span1">\n' +
                                                            '                                </div>\n'
                                                    }
                                                }

                                                btnStr += '                        </div>\n'
                                            } else {
                                                statusStr = '待审核'
                                                showStr = '隐藏中'
                                                dateStr = formatDate(el.ctime)
                                                btnStr =  '                            <div class="bui-box">\n' +
                                                    '                                <div class="span1">\n' +
                                                    '                                    <div class="czbtn edit" style="font-size: '+fontSize2+'" name="'+el.id+'" cate="'+el.cate+'">\n' +
                                                    '                                        编辑\n' +
                                                    '                                    </div>\n' +
                                                    '                                </div>\n' +
                                                    '                                <div class="span1 btnBorder">\n' +
                                                    '                                    <div class="czbtn delete" style="font-size: '+fontSize2+'" name="'+el.id+'" cate="'+el.cate+'" city="'+el.city+'" country="'+el.country+'" status="'+el.status+'" delFlag="'+el.delFlag+'" page="'+el.page+'" jobId="'+el.jobId+'">\n' +
                                                    '                                        删除\n' +
                                                    '                                    </div>\n' +
                                                    '                                </div>\n'

                                                let cs = 0
                                                if((user.qxStr && user.qxStr.indexOf("0") > -1) || user.userId == '1' || (user.adminType && user.adminType == '0')) {
                                                    btnStr +=  '                                <div class="span1 btnBorder">\n' +
                                                        '                                    <div class="czbtn audit" style="font-size: '+fontSize2+'" name="'+el.id+'">\n' +
                                                        '                                        审核\n' +
                                                        '                                    </div>\n' +
                                                        '                                </div>\n'
                                                } else {
                                                    cs = 1
                                                }
                                                if ((user.adminType && user.adminType == '0') || user.userId == '1') {
                                                    btnStr += '                                <div class="span2 btnBorder">\n' +
                                                        '                                    <div class="czbtn cdsc" style="font-size: '+fontSize2+'" name="'+el.id+'" cate="'+el.cate+'" city="'+el.city+'" country="'+el.country+'" status="'+el.status+'" delFlag="'+el.delFlag+'" page="'+el.page+'" jobId="'+el.jobId+'">\n' +
                                                        '                                        彻底删除\n' +
                                                        '                                    </div>\n' +
                                                        '                                </div>\n'
                                                } else {
                                                    btnStr += '                                <div class="span1">\n' +
                                                        '                                </div>\n'
                                                    if (cs == 1) {
                                                        btnStr += '                                <div class="span1">\n' +
                                                            '                                </div>\n'
                                                    }
                                                }

                                                btnStr += '                        </div>\n'
                                            }
                                        } else {
                                            statusStr = '已删除'
                                            showStr = '隐藏中'
                                            dateStr = formatDate(el.ctime)
                                            if ((user.adminType && user.adminType == '0') || user.userId == '1') {
                                                btnStr = '                            <div class="bui-box">\n' +
                                                    '                                <div class="span2">\n' +
                                                    '                                    <div class="czbtn cdsc" style="font-size: '+fontSize2+'" name="'+el.id+'" cate="'+el.cate+'" city="'+el.city+'" country="'+el.country+'" status="'+el.status+'" delFlag="'+el.delFlag+'" page="'+el.page+'" jobId="'+el.jobId+'">\n' +
                                                    '                                        彻底删除\n' +
                                                    '                                    </div>\n' +
                                                    '                                </div>\n'+
                                                    '                                <div class="span1 btnBorder">\n' +
                                                    '                                    <div class="czbtn hf" style="font-size: '+fontSize2+'" name="'+el.id+'" cate="'+el.cate+'" city="'+el.city+'" country="'+el.country+'" jobId="'+el.jobId+'">\n' +
                                                    '                                        恢复\n' +
                                                    '                                    </div>\n' +
                                                    '                                </div>\n'+
                                                    '                                <div class="span1">\n' +
                                                    '                                </div>\n'+
                                                    '                                <div class="span1">\n' +
                                                    '                                </div>\n'+
                                                    '                        </div>\n'
                                            }
                                        }
                                    } else {
                                        btnStr = '                            <div class="bui-box">\n' +
                                            '                                <div class="span1">\n' +
                                            '                                    <div class="czbtn delete" style="font-size: '+fontSize2+'" name="'+el.id+'" cate="'+el.cate+'" city="'+el.city+'" country="'+el.country+'" status="'+el.status+'" delFlag="'+el.delFlag+'" page="'+el.page+'" jobId="'+el.jobId+'">\n' +
                                            '                                        删除\n' +
                                            '                                    </div>\n' +
                                            '                                </div>\n'

                                        if (el.delFlag == '0') {
                                            if(el.status == '0'){
                                                btnStr +=  '                                <div class="span1">\n' +
                                                '                                </div>\n'
                                                statusStr = '审核失败'
                                                showStr = '隐藏中'
                                                dateStr = formatDate(el.ctime)
                                            } else if (el.status == '1') {
                                                btnStr  +=  '                                <div class="span2 btnBorder">\n' +
                                                    '                                    <div class="czbtn scQrcode" style="font-size: '+fontSize2+'" name="'+el.id+'" glUserid="'+el.glUserid+'" cateStr="'+el.cateStr+'" contentText="'+el.contentText+'" titleStr="'+el.title+'" dateStr="'+dateStr+'" cityStr="'+el.cityStr+'" imgCs="'+el.imgCs+'" avater="'+el.avater+'" userStr="'+el.userStr+'">\n' +
                                                    '                                        生成二维码\n' +
                                                    '                                    </div>\n' +
                                                    '                                </div>\n'
                                                statusStr = '已发布'
                                                showStr = '展示中'
                                                dateStr = formatDate(el.ptime)
                                            } else {
                                                btnStr +=  '                                <div class="span1">\n' +
                                                    '                                </div>\n'
                                                statusStr = '待审核'
                                                showStr = '隐藏中'
                                                dateStr = formatDate(el.ctime)
                                            }
                                        } else {
                                            btnStr +=  '                                <div class="span1">\n' +
                                                '                                </div>\n'
                                            statusStr = '已删除'
                                            showStr = '隐藏中'
                                            dateStr = formatDate(el.ctime)
                                        }
                                        btnStr += '                        </div>\n'
                                    }

                                    let uv = 0
                                    if (el.uv) {
                                        uv = el.uv
                                    }
                                    let views = 0
                                    if (el.views) {
                                        views = el.views
                                    }
                                    let comments = 0
                                    if (el.comments) {
                                        comments = el.comments
                                    }
                                    let tel = ''
                                    if (el.tel) {
                                        tel = el.tel
                                    }
                                    let wx = ''
                                    if (el.wx) {
                                        wx = el.wx
                                    }
                                    let email = ''
                                    if (el.email) {
                                        email = el.email
                                    }
                                    let isfix = '未开启'
                                    if (el.isfix == '1') {
                                        isfix = '开启'
                                    }
                                    let isfix1 = '未开启'
                                    if (el.isfix1 == '1') {
                                        isfix1 = '开启'
                                    }
                                    let refrsh = '未开启'
                                    if (el.refresh == '1') {
                                        refrsh = '开启'
                                    }
                                    let refreshtime = '默认时间'
                                    if (el.refresh == '1') {
                                        refreshtime = formatDateTime(el.refreshtime)
                                    }
                                    html += '<li class="bui-btn">\n'


                                    if (title) {
                                        html += '<p style="color: black;font-size: '+fontSize+';">'+
                                            '<span>【'+el.cateStr+'】</span>'
                                        let titles = el.title.split(title)
                                        titles.forEach(function(str, index) {
                                            html += '<span >'+str+'</span>'
                                            if (index < titles.length - 1) {
                                                html += '<span style="color: red;">'+title+'</span>'
                                            }
                                        })
                                        html += '</p>'

                                        if (el.contentText) {
                                            html += '<p style="color: rgb(120,120,120);font-size: '+fontSize3+';">'

                                            let contentTexts = el.contentText.split(title)
                                            let xzLength = 100
                                            if (el.contentText.length < xzLength) {
                                                contentTexts.forEach(function(str, index) {
                                                    html += '<span>'+str+'</span>'
                                                    if (index < contentTexts.length - 1) {
                                                        html += '<span style="color: red;">'+title+'</span>'
                                                    }
                                                })
                                            } else {
                                                let len = search.length
                                                contentTexts.forEach(function(el, index) {
                                                    if (len <= xzLength) {
                                                        if (el.length > xzLength - len) {
                                                            let str = el.substring(el.length - (xzLength - len), el.length)
                                                            html += '<span>...'+str+'</span>'
                                                        } else {
                                                            html += '<span>'+el+'</span>'
                                                        }
                                                        len += el.length
                                                        if (index < contentTexts.length - 1) {
                                                            html += '<span style="color: red;">'+title+'</span>'
                                                        }
                                                    }
                                                })
                                            }
                                            html += '<p>'
                                        }
                                    } else {
                                        html += '                        <p style="color: black;font-size: '+fontSize+';">【'+el.cateStr+'】'+el.title+'</p>\n'
                                        if (el.contentText) {
                                            html += '                        <p style="color: rgb(120,120,120);font-size: '+fontSize3+';margin-bottom: 0.22rem">'+el.contentText.substring(0,100)
                                            if(el.contentText.length > 100) {
                                                html += '...'
                                            }
                                            html += '</p>\n'
                                        }
                                    }

                                    html += '                        <div class="bui-box" style="margin-bottom: 20px">\n' +
                                    '                            <div class="span1">\n' +
                                    '                                <div class="bui-box" style="margin-bottom: 10px">\n' +
                                    '                                    <div class="span1 item-text"><span class="bui-label" style="font-size: '+fontSize2+'">'+showStr+'</span></div>\n' +
                                    '                                    <div class="span2 item-text" style="font-size: '+fontSize2+'">'+dateStr+'</div>\n' +
                                    '                                    <div class="span1 item-text"><span class="bui-label" style="font-size: '+fontSize2+'">'+statusStr+'</span></div>\n' +
                                    '                                </div>\n' +
                                    '                                <div class="bui-box" style="margin-bottom: 10px">\n' +
                                    '                                    <div class="span1 item-text"><span class="bui-label" style="font-size: '+fontSize2+'">访问量 '+views+'</span></div>\n' +
                                    '                                    <div class="span1 item-text"><span class="bui-label" style="font-size: '+fontSize2+'">UV '+uv+'</span></div>\n' +
                                    '                                    <div class="span1 item-text"><span class="bui-label" style="font-size: '+fontSize2+'">留言 '+comments+'</span></div>\n' +
                                    '                                </div>\n' +
                                    '                                <div class="bui-box">\n' +
                                    '                                    <div class="span1 item-text"><span class="bui-label" style="font-size: '+fontSize2+'">当日访问量 '+el.pvDay+'</span></div>\n' +
                                    '                                    <div class="span1 item-text"><span class="bui-label" style="font-size: '+fontSize2+'">当日UV '+el.uvDay+'</span></div>\n' +
                                    '                                    <div class="span1 item-text"><span class="bui-label"></span></div>\n' +
                                    '                                </div>\n' +
                                    '                            </div>\n' +
                                    '                            <div class="czbtn2 article" style="background: rgb(252,84,49); font-size: '+fontSize2+';" name="'+el.id+'" glUserid="'+el.glUserid+'">详情</div>\n' +
                                    '                        </div>\n' +
                                    '                        <p class="item-text" style="font-size: '+fontSize2+' !important;"><span class="bui-label">手机号 </span><span class="bui-value">'+tel+'</span></p>\n' +
                                    '                        <p class="item-text" style="font-size: '+fontSize2+' !important;"><span class="bui-label">微信号 </span><span class="bui-value">'+wx+'</span></p>\n' +
                                    '                        <p class="item-text" style="font-size: '+fontSize2+' !important;"><span class="bui-label">邮箱 </span><span class="bui-value">'+email+'</span></p>\n' +
                                    '                        <div class="bui-box" style="margin-bottom: 20px">\n' +
                                    '                            <div class="span1">\n' +
                                    '                                <div class="bui-box" style="margin-bottom: 10px;">\n' +
                                    '                                    <div class="span2 item-text"><span class="bui-label" style="font-weight: bold;font-size: '+fontSize2+'">首页置顶</span></div>\n' +
                                    '                                    <div class="span1 item-text" style="font-size: '+fontSize2+'">'+isfix+'</div>\n' +
                                    '                                </div>\n' +
                                    '                            </div>\n'
                                    if (el.isfix == '1') {
                                        html +=  '                            <div class="span1">\n' +
                                            '                                <div class="bui-box" style="margin-bottom: 10px;">\n' +
                                            '                                    <div class="span1 item-text"><span class="bui-label" style="font-weight: bold;font-size: '+fontSize2+'">结束时间</span></div>\n' +
                                            '                                    <div class="span1 item-text" style="font-size: '+fontSize2+'">'+formatDate(el.fixexp)+'</div>\n' +
                                            '                                </div>\n' +
                                            '                            </div>\n'
                                    } else {
                                        html +=  '                            <div class="span1">\n' +
                                            '                            </div>\n'
                                    }
                                        html += '                        </div>\n'+
                                            '                        <div class="bui-box" style="margin-bottom: 20px;">\n' +
                                            '                            <div class="span1">\n' +
                                            '                                <div class="bui-box" style="margin-bottom: 10px">\n' +
                                            '                                    <div class="span2 item-text"><span class="bui-label" style="font-weight: bold; font-size: '+fontSize2+'">分类页置顶</span></div>\n' +
                                            '                                    <div class="span1 item-text" style="font-size: '+fontSize2+'">'+isfix1+'</div>\n' +
                                            '                                </div>\n' +
                                            '                            </div>\n'
                                    if (el.isfix1 == '1') {
                                        html +=  '                            <div class="span1">\n' +
                                            '                                <div class="bui-box" style="margin-bottom: 10px;">\n' +
                                            '                                    <div class="span1 item-text"><span class="bui-label" style="font-weight: bold;font-size: '+fontSize2+'">结束时间</span></div>\n' +
                                            '                                    <div class="span1 item-text" style="font-size: '+fontSize2+'">'+formatDate(el.fixexp1)+'</div>\n' +
                                            '                                </div>\n' +
                                            '                            </div>\n'
                                    } else {
                                        html +=  '                            <div class="span1">\n' +
                                            '                            </div>\n'
                                    }
                                    html += '                        </div>\n'+
                                        '                        <div class="bui-box" style="margin-bottom: 20px">\n' +
                                        '                            <div class="span1">\n' +
                                        '                                <div class="bui-box" style="margin-bottom: 10px;">\n' +
                                        '                                    <div class="span2 item-text"><span class="bui-label" style="font-weight: bold; font-size: '+fontSize2+';">自动刷新</span></div>\n' +
                                        '                                    <div class="span1 item-text" style="font-size: '+fontSize2+'">'+refrsh+'</div>\n' +
                                        '                                </div>\n' +
                                        '                            </div>\n'
                                    if (el.refresh == '1') {
                                        html +=   '                            <div class="span1">\n' +
                                        '                                <div class="bui-box" style="margin-bottom: 10px;">\n' +
                                        '                                    <div class="span1 item-text"><span class="bui-label" style="font-weight: bold;font-size: '+fontSize2+'">刷新时间</span></div>\n' +
                                        '                                    <div class="span1 item-text" style="font-size: '+fontSize2+'">'+refreshtime+'</div>\n' +
                                        '                                </div>\n' +
                                        '                            </div>\n'
                                    } else {
                                        html +=  '                            <div class="span1">\n' +
                                            '                            </div>\n'
                                    }
                                    html += '</div>'
                                    if (el.refresh == '1') {
                                        html += '                        <div class="bui-box" style="margin-bottom: 20px">\n' +
                                            '                            <div class="span1">\n' +
                                            '                                <div class="bui-box" style="margin-bottom: 10px;">\n' +
                                            '                                    <div class="span1 item-text"><span class="bui-label" style="font-weight: bold; font-size: '+fontSize2+'">剩余刷新</span></div>\n' +
                                            '                                    <div class="span1 item-text" style="font-size: '+fontSize2+'">'+el.refreshcount+'次</div>\n' +
                                            '                                </div>\n' +
                                            '                            </div>\n'+
                                            '                            </div>\n'
                                    }

                                    html += btnStr+'                    </li>'
                                });
                                uiLoading.stop()

                                setTimeout(function () {
                                    try {
                                        translate.execute();
                                    }catch (e) {
                                        console.log("切换语言报错")
                                    }
                                },1000)
                                return html;
                            }
                        })

                        //查询分类
                        bui.ajax({
                            url: global.api.termTypeTree,
                            method: "POST"
                        }).then(function(res){
                            let dqList = res.data
                            if (dqList) {
                                let zzList = [{id: '', label: '全部', lx: '0'}]
                                zzList = zzList.concat(dqList)
                                // 设置值
                                bui.levelselect({
                                    data: zzList,
                                    title: "所属分类",
                                    trigger: ".selected-vals2",
                                    level: 2,
                                    field: {
                                        name: "label",
                                        data: ["children"],
                                    },
                                    value: ['全部'],
                                    autoClose: true,
                                    onChange: function (e, currentData, nextData) {
                                        let sj = $(e.target).parent()
                                        let id = sj.children("input").attr("id")
                                        let lx = sj.children("input").attr("lx")
                                        if (lx && ss === 1) {
                                            if (lx == '2' || lx == '0') {
                                                cate = id
                                                uiList.replace({
                                                    data:{
                                                        cate: cate,
                                                        glUserid: glUserid,
                                                        status: status,
                                                        delFlag: delFlag,
                                                        isfix: isfix,
                                                        isfix1: isfix1,
                                                        title: title
                                                    }
                                                });
                                            }
                                        }
                                    }
                                })
                            }
                        })
                        //查询来源
                        bui.ajax({
                            url: global.api.lyUser,
                            method: "POST",
                            headers: {Token: token}
                        }).then(function(res){
                            let dqList = res.data
                            if (dqList) {
                                let zzList = [{value: '-1', name: '全部'}]
                                zzList = zzList.concat(dqList)
                                bui.select({
                                    trigger: "#provinceSelect",
                                    title: "文章来源",
                                    type: "radio",
                                    autoClose: true,
                                    value: ['全部'],
                                    data: zzList,
                                    height: 300,
                                    onChange: function (e) {
                                        // let val = lySelect.value();
                                        glUserid = this.value()
                                        if (glUserid == '-1') {
                                            glUserid = ''
                                        }
                                        if (ss === 1)  {
                                            uiList.replace({
                                                data:{
                                                    cate: cate,
                                                    glUserid: glUserid,
                                                    status: status,
                                                    delFlag: delFlag,
                                                    isfix: isfix,
                                                    isfix1: isfix1,
                                                    title: title
                                                }
                                            });
                                        }
                                    }
                                });
                            }
                        })
                        //状态下拉框
                        bui.select({
                            trigger: "#statusSelect",
                            title: "文章状态",
                            type: "radio",
                            autoClose: true,
                            value: ['全部'],
                            data: [{value: '-1', name: '全部'},{value: '1', name: '发布'},{value: '2', name: '待审核'},{value: '0', name: '审核失败'},{value: '3', name: '已删除'}],
                            height: 300,
                            onChange: function (e) {
                                let sta = this.value()
                                if (sta != '-1') {
                                    if (sta === '3') {
                                        delFlag = '1'
                                        status = ''
                                    } else {
                                        delFlag = '0'
                                        status = sta
                                    }
                                } else {
                                    delFlag = ''
                                    status = ''
                                }

                                if (ss === 1){
                                    uiList.replace({
                                        data:{
                                            cate: cate,
                                            glUserid: glUserid,
                                            status: status,
                                            delFlag: delFlag,
                                            isfix: isfix,
                                            isfix1: isfix1,
                                            title: title
                                        }
                                    });
                                }
                            }
                        });
                        //置顶下拉框
                        bui.select({
                            trigger: "#zdSelect",
                            title: "文章置顶",
                            type: "radio",
                            autoClose: true,
                            value: ['全部'],
                            data: [{value: '-1', name: '全部'},{value: '1', name: '首页置顶'},{value: '2', name: '分类页置顶'}],
                            height: 300,
                            onChange: function (e) {
                                let zd = this.value()
                                if (zd != '-1') {
                                    if (zd === '1') {
                                        isfix = '1'
                                        isfix1 = ''
                                    } else {
                                        isfix = ''
                                        isfix1 = '1'
                                    }
                                } else {
                                    isfix = ''
                                    isfix1 = ''
                                }

                                if (ss === 1) {
                                    uiList.replace({
                                        data:{
                                            cate: cate,
                                            glUserid: glUserid,
                                            status: status,
                                            delFlag: delFlag,
                                            isfix: isfix,
                                            isfix1: isfix1,
                                            title: title
                                        }
                                    });
                                }
                            }
                        });
                        //搜索框
                        router.$('#search').bind('keypress',function(event){//监听sim卡回车事件
                            if(event.keyCode == "13")
                            {
                                title = $(this).val()
                                uiList.replace({
                                    data:{
                                        cate: cate,
                                        glUserid: glUserid,
                                        status: status,
                                        delFlag: delFlag,
                                        isfix: isfix,
                                        isfix1: isfix1,
                                        title: title
                                    }
                                });
                            }
                        });

                        router.$("#searchBtn").click(function () {
                            title = router.$("#search").val()
                            uiList.replace({
                                data:{
                                    cate: cate,
                                    glUserid: glUserid,
                                    status: status,
                                    delFlag: delFlag,
                                    isfix: isfix,
                                    isfix1: isfix1,
                                    title: title
                                }
                            });
                        })
                    }
                })
            } else {
                bui.confirm({
                    "title": "",
                    "height": 460,
                    "content": '<div class="bui-box-center"><div><h3>当前未登录，请登录</h3></div></div>',
                    "buttons": [{ name: "登录", className: "primary-reverse" }],
                    callback:function(){
                        this.close();
                        storage.set("dlTz", '11')
                        router.replace({ url: "pages/login/login.html", param:{tzSign: '0'}});
                    }
                });
            }
        }
    };

    // 初始化
    pageview.init();

    // 输出模块
    return pageview;
})

function formatDate(time) {
    if (time) {
        let date = new Date(time * 1000);
        // let now = new Date();
        // let days=parseInt((now - date) / (1000 * 60 * 60* 24) + '');
        // if (days > 7){
        let Y = date.getFullYear() + '-';
        let M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        let D = (date.getDate() < 10 ? '0'+(date.getDate()) : date.getDate()) + ' ';
        let h = (date.getHours() < 10 ? '0'+(date.getHours()) : date.getHours()) + ':';
        let m = (date.getMinutes() < 10 ? '0'+(date.getMinutes()) : date.getMinutes());
        return Y+M+D+h+m
        // } else if (days < 1) {
        //     let hour=parseInt((now - date) / (1000 * 60 * 60) + '');
        //     return hour + "小时前"
        // }
        // return days + "天前"
    }
    return ""
}
function formatDateTime(time) {
    let date = new Date(time * 1000);

    let h = (date.getHours()+1 < 10 ? '0'+(date.getHours()+1) : date.getHours()+1) + ':';
    let m = (date.getMinutes() < 10 ? '0'+(date.getMinutes()) : date.getMinutes()) + ':';
    let s = (date.getSeconds() < 10 ? '0'+(date.getSeconds()) : date.getSeconds());
    return h+m+s
}
function downloadImg(src,type="url") {
    let image = new Image();
    if(type==="url"){
        image.src = src + '?v=' + Math.random(); // 处理缓存
    }else{
        image.src = src;
    }
    image.crossOrigin = '*';  // 支持跨域图片
    image.onload = function () {
        let canvas = document.createElement('canvas');
        canvas.width = image.width;
        canvas.height = image.height;
        let ctx = canvas.getContext('2d');
        ctx.drawImage(image, 0, 0, image.width, image.height);
        let dataURL = canvas.toDataURL('image/png');  // 可选其他值 image/jpeg
        let a = document.createElement('a');
        let event = new MouseEvent('click');
        a.download = '推广二维码';
        a.href = dataURL;
        a.dispatchEvent(event);
    };
}

function isMobile() {
    let userAgentInfo = navigator.userAgent;

    let mobileAgents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];

    let mobile_flag = false;

    let ua = navigator.userAgent.toLowerCase()
    if (ua.match(/MicroMessenger/i) == "micromessenger") {
        mobile_flag = true
    } else {
        //根据userAgent判断是否是手机
        for (let v = 0; v < mobileAgents.length; v++) {
            if (userAgentInfo.indexOf(mobileAgents[v]) > 0) {
                mobile_flag = true;
                break;
            }
        }
    }

    return mobile_flag;
}

function isWeiXin() {
    let ua = navigator.userAgent.toLowerCase()
    if (ua.match(/MicroMessenger/i) == "micromessenger") {
        return true
    } else {
        return false
    }
}
